package com.glory.eapequipmentmonitor.adapter;

import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.eapequipmentmonitor.R;
import com.glory.eapequipmentmonitor.bean.CheckBean;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import java.util.List;


public class CheckListAdapter extends BaseQuickAdapter<CheckBean, BaseViewHolder> {

    public CheckListAdapter(@Nullable List<CheckBean> data) {
        super(R.layout.adapter_check_list, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, final CheckBean item) {
        TextView tvCheckTitle = helper.getView(R.id.tvCheckTitle);
        LinearLayout llContent = helper.getView(R.id.llContent);
        if (item.getTitle().length() > 0) {
            tvCheckTitle.setVisibility(View.VISIBLE);
            tvCheckTitle.setText(item.getTitle());
            llContent.setVisibility(View.GONE);
        } else {
            tvCheckTitle.setVisibility(View.GONE);
            llContent.setVisibility(View.VISIBLE);
            helper.setText(R.id.tvName, item.getDataName());

            FreeUI_ClearEditText etRemark = helper.getView(R.id.etRemark);
            etRemark.setText(item.getDataValue());
            etRemark.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    item.setDataValue(charSequence.toString());
                }

                @Override
                public void afterTextChanged(Editable editable) {

                }
            });
        }
    }
}
